<?php
class SellersettingModel extends Model {
	protected $autoCheckFields = false;
	public function getPaytype( $recharge = '0' ) {
		$where = $recharge == 1 ? "id=1" : "";
		return D ( 'Paymenttype' )->where ( $where )->select ();
	}
	public function getPaytypeOne ( $typeid ) {
		return D('Paymenttype')->where("id={$typeid}")->find();
	}
	public function getSellerByID ( $id ) {
		return D('Seller')->where("id={$id}")->find();
	}
	public function getSellerByNick ( $nick ) {
		return D('Seller')->where("nick='{$nick}'")->find();
	}
	
	public function createPayCode(){
		return date("YmdHis").rand_string(6,1);
	}
	
	public function getPaymentCount( $user_id=null ) {
		if($user_id) $where = "user_id={$user_id}";
		return D("payment")->where($where)->count();
	}
	public function getPayment ( $user_id , $offset='0', $limit='10' ) {
		if( $offset && $limit ) $limit = $offset. ',' .$limit;
		return D("payment")->where("user_id={$user_id}")->limit( $limit )->order("paydate DESC")->select();
	}
}